package com.exp.bookhouse.util;

import java.security.MessageDigest;

//MD5加密
public class CodeUtil {

    //加密
    public static String encode(String password) {
        byte[] unencodedPassword = password.getBytes();
        MessageDigest md = null;
        try {
            md = MessageDigest.getInstance("MD5");
        } catch (Exception e) {
            return password;
        }
        md.reset();
        md.update(unencodedPassword);
        byte[] encodedPassword = md.digest();
        StringBuffer buf = new StringBuffer();
        for (int i = 0; i < encodedPassword.length; i++) {
            if ((encodedPassword[i] & 0xFF) < 16) {
                buf.append("0");
            }
            buf.append(Long.toString(encodedPassword[i] & 0xFF, 16));
        }
        return buf.toString();
    }


   /* public static void main(String[] args) {
        String encode = CodeUtil.encode("123");
        System.out.println(encode);
    }*/
 
}